// $Id: h264.h 113 2011-11-28 17:07:05Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef H264_H_
#define H264_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <sys/time.h>
#include <event.h>
#include <niohttp/h264.h>

#include "transport.h"

struct timeval;

struct zcbuffer;

#define H264_NRI_MAX 4

struct niohttp_h264 {
	struct event_base *evbase;
	char *type;
	char *boundary;
	int setup;
	int fd;
	struct niohttp_transport_param param;
	struct event ev;
	struct timeval tv;
	struct niohttp_transport_stat old;
	struct niohttp_transport_stat new;
	struct zcqueue *queues[H264_NRI_MAX];
	struct zcqueue *dropping;
	size_t num_gops;
	struct {
		struct timeval incoming;
		struct timeval outgoing;
	} latest;
	struct timeval previous;
	struct timeval timestamp;
	struct evbuffer *header;
	struct zcbuffer *buffer;
	struct timeval start;
	int refreshed;
};

void *niohttp_h264_create(struct event_base *evbase);

void niohttp_h264_destroy(void *obj);

int niohttp_h264_setup(void *obj, int fd, struct niohttp_transport_param *param);

int niohttp_h264_teardown(void *obj);

int niohttp_h264_send(void *obj, const struct timeval *timestamp,
		struct zcbuffer *frame);

int niohttp_h264_pending(void *obj);

int niohttp_h264_next(void *obj);

int niohttp_h264_stat(void *obj, struct niohttp_transport_stat *stat);

#ifdef __cplusplus
}
#endif

#endif /* H264_H_ */
